package audio;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class AudioPlayer {

		private static void suona(String filename){
			File s = new File(filename);
			try {
				AudioFileFormat aff = AudioSystem.getAudioFileFormat(s);
				AudioInputStream ais= AudioSystem.getAudioInputStream(s);
				AudioFormat af= aff.getFormat();
				DataLine.Info info = new DataLine.Info(
						Clip.class,
						ais.getFormat(),
						((int) ais.getFrameLength()) * af.getFrameSize());
				try {
					Clip ol = (Clip) AudioSystem.getLine(info);
					ol.open(ais);
					ol.loop(0);
				} catch (LineUnavailableException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
					
			} catch (UnsupportedAudioFileException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		
		
		public static void suonaBomba(){
			suona("099.wav");
		}
		
		public static void suonaDardo(){
			suona("022.wav");
		}
		
		public static void suonaAbilitaBiobot(){
			suona("047.wav");
		}
		
		public static void suonaAbilitaFastbot(){
			suona("102.wav");
		}
		
		public static void suonaAbilitaTechnobot(){
			suona("038.wav");
		}
		
		public static void suonaAbilitaBombobot(){
			suona("089.wav");
		}
		
		
		
		
}